package errno

import "fmt"

// Errno 定义错误码和信息
type Errno struct {
	Code    int
	Message string
}

func (err Errno) Error() string {
	return err.Message
}

// Err 定义错误
type Err struct {
	Code    int
	Message string
	Errors  error
}

func (e *Err) Error() string {
	return fmt.Sprintf("Err - code:%d, message: %s,error:%s", e.Code, e.Message, e.Error())
}

func New(errno *Errno, err error) *Err {
	return &Err{
		Code:    errno.Code,
		Message: errno.Message,
		Errors:  err,
	}
}

var (
	OK   = &Errno{Code: 0, Message: "OK"}
	Fail = &Errno{Code: -1, Message: "Fail"}

	// 系统错误, 前缀为 100
	InternalServerError = &Errno{Code: 10001, Message: "内部服务器错误"}
	ErrBind             = &Errno{Code: 10002, Message: "请求参数错误"}
	ErrTokenSign        = &Errno{Code: 10003, Message: "签名 token 时发生错误"}
	ErrEncrypt          = &Errno{Code: 10004, Message: "加密用户密码时发生错误"}

	// 数据库错误, 前缀为 201
	ErrDatabase = &Errno{Code: 20100, Message: "数据库错误"}
	ErrFill     = &Errno{Code: 20101, Message: "从数据库填充 struct 时发生错误"}

	// 认证错误, 前缀是 202
	ErrValidation     = &Errno{Code: 20201, Message: "验证失败"}
	ErrTokenInvalid   = &Errno{Code: 20202, Message: "token为空或无效"}
	ErrTokenExpired   = &Errno{Code: 20203, Message: "token已过期"}
	ErrTokenSetUpFail = &Errno{Code: 20204, Message: " token 生成失败"}

	// 用户错误, 前缀为 203
	ErrUserNotFound         = &Errno{Code: 20301, Message: "用户没找到"}
	ErrPasswordIncorrect    = &Errno{Code: 20302, Message: "密码错误"}
	ErrUserNotRights        = &Errno{Code: 20303, Message: "没有权限"}
	ErrUserNotInRecruirRang = &Errno{Code: 20304, Message: "不在招募范围内"}
	// 活动错误， 前缀 204
	ErrActivityNotExist   = &Errno{Code: 20401, Message: "活动不存在"}
	ErrActivityRunning    = &Errno{Code: 20402, Message: "活动正在进行中"}
	ErrActivityNotRecruit = &Errno{Code: 20403, Message: "活动不可参加，请检查活动状态"}
	ErrActivityForbidQuit = &Errno{Code: 20404, Message: "活动不可退出，请检查活动状态"}
	ErrActivityLimits     = &Errno{Code: 20405, Message: "活动人员已招募完成"}
	ErrActivityHasJoinIn  = &Errno{Code: 20406, Message: "不可重复参加同一活动"}

	// 数据验证， 前缀 205
	ErrValidateFail = &Errno{Code: 20501, Message: "数据验证失败"}

	// 参数解析错误 前缀 206

	ErrParseParameter = &Errno{Code: 20601, Message: "参数解析错误"}
)
